package com.niit.onlinemusicserver34.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.niit.onlinemusicserver34.common.R;
import com.niit.onlinemusicserver34.mapper.AdminMapper;
import com.niit.onlinemusicserver34.model.domain.Admin;
import com.niit.onlinemusicserver34.model.request.AdminRequest;
import com.niit.onlinemusicserver34.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    @Autowired
    AdminMapper adminMapper;

    @Override
    public R verifyPasswd(AdminRequest adminRequest, HttpSession session) {
        // where name = ? and password = ?
        QueryWrapper<Admin> wrapper =  new QueryWrapper<>();
        wrapper.eq("name",adminRequest.getUsername());
        wrapper.eq("password",adminRequest.getPassword());


        if(adminMapper.selectCount(wrapper)>0){

            session.setAttribute("username",adminRequest.getUsername());

            return R.success("登录成功！");
        }
        return R.fatal("登录失败！");
    }
}
